IF exists(SELECT * FROM dbo.sysobjects WHERE name='SGvulKeuzes' AND xtype='P') 
BEGIN
	DROP PROCEDURE SGvulKeuzes
END
GO

CREATE    procedure SGvulKeuzes
as
insert into SGkeuzes(naamcode,codeschool)
select s.naamcode,s.codeschool from
SGpersoneel as s left join
SGkeuzes as k
on s.naamcode=k.naamcode and s.codeSchool=k.codeSchool
where k.naamcode is null

delete SGkeuzes
from SGkeuzes as s
left join  SGpersoneel as p
      on s.naamcode=p.naamcode and s.codeschool=p.codeschool
	
where p.naamcode is null 